package com.hyyt.shopjsp.customer.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyyt.shopjsp.basic.service.IBasicActorPurviewService;
import com.hyyt.shopjsp.common.controller.BaseController;
import com.hyyt.shopjsp.customer.pojo.ShopCustomerDiscountCoupon;
import com.hyyt.shopjsp.customer.service.IShopCustomerDiscountCouponService;
import com.hyyt.shopjsp.util.common.Page;
import com.hyyt.shopjsp.util.common.ResultMsg;
import com.hyyt.shopjsp.util.common.Utils;

/**
 * Copyright (c) 2017 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
 * @author Wang Youchun on 2017/3/31 0024下午 16:53.
 */
@Controller
@RequestMapping("/back/discountcoupon")
public class ShopCustomerDiscountcouponController extends BaseController {
	private Logger log = Logger.getLogger(ShopCustomerDiscountcouponController.class);
	private String basePath = "/back/discountcoupon/";
	@Resource
	private IShopCustomerDiscountCouponService shopCustomerDiscountCouponService;//用户优惠券描述信息
	/**
	 * 进入会员优惠券信息管理
	 *
	 * @return 进入指定页面
	 */
	@RequestMapping("gotoCustomerdiscount")
	public String gotoCustomerdiscount(){
		return basePath+"customerdisountCouponList";
	}

	/**
	 * 查询所有会员优惠券信息
	 * @param page
	 * @param response
	 * @param request
	 */
	@RequestMapping(value="selcetCustomerdiscount",method=RequestMethod.POST)
	@ResponseBody
	public void selcetCustomerdiscount(String discountCouponName,String discountCouponCode,String loginName,String useStatus,String beginTime,String expirationTime,Page page, HttpServletResponse response, HttpServletRequest request){
		Map<String, Object> param = new HashMap<>();
		if (Utils.objectIsNotEmpty(discountCouponName)) {//是否检索劵名称
			param.put("discountCouponName", discountCouponName.trim());
		}
		if (Utils.objectIsNotEmpty(discountCouponCode)) {//是否检索劵码
			param.put("discountCouponCode", discountCouponCode.trim());
		}
		if (Utils.objectIsNotEmpty(loginName)) {//是否检索会员名称
			param.put("loginName", loginName.trim());
		}
		if (Utils.objectIsNotEmpty(useStatus)) {//是否检索使用状态
			param.put("useStatus", useStatus);
		}
		if (Utils.objectIsNotEmpty(beginTime)) {//是否检索活动时间
			param.put("beginTime", beginTime);
		}
		if (Utils.objectIsNotEmpty(expirationTime)) {//是否检索活动时间
			param.put("expirationTime", expirationTime);
		}
		param.put("sortColumns", "customerDiscountCouponID desc");
		int totalRecordCount =shopCustomerDiscountCouponService.countShopCustomerDiscountCoupon(param);
		page.setPageInfo(page.getPageSize(), totalRecordCount, page.getCurrentPage());
		List<ShopCustomerDiscountCoupon> customerdiscountcouponlist =shopCustomerDiscountCouponService.queryShopCustomerDiscountCoupon(param, page.getPageRecordBeginIndex(), page.getPageSize());
		param.clear();
		param.put("total", totalRecordCount);// total键 存放总记录数，必须的
		param.put("rows", customerdiscountcouponlist);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}


}